<?php
declare(strict_types=1);

namespace App\AdminApi\Module\System\Crontab;

use App\AdminApi\Module\System\Service\CachingService;
use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Di\Annotation\Inject;

class CachingCrontab
{
    #[Inject]
    protected CachingService $serve;

    /**
     *  清理过期缓存提升性能
     */
    #[Crontab(rule: "0 */5 * * *", name: "clean.expired.cache", memo: "清理失效缓存,优化缓存性能,每5小时执行一次")]
    public function cleanExpiredCache(): void
    {
        $this->serve->search("(`expiration_time`>0 AND `expiration_time`<?)", [time()])->delete();
    }
}